package com.zrt.utils.string;

import org.apache.commons.lang3.StringUtils;

/**
 * 字符串处理工具类
 *
 * @author 庄锐涛
 * @since 1.0.0
 */
public class StringUtil extends StringUtils {

    /**
     * 判断字符串数组或列表是否包含null或空白字符串对象
     *
     * <pre>
     * StringUtils.isContainEmpty(null,"xxx")           = true
     * StringUtils.isContainEmpty("","xxx")            =true
     * StringUtils.isContainEmpty(" ","xxx")          =true
     * StringUtils.isContainEmpty("bob","xxx")       =false
     * StringUtils.isContainEmpty(" bob  ","xxx")   =false
     * </pre>
     */
    public static boolean isContainBlank(String... args) {
        if (args == null) {
            return false;
        }
        for (String arg : args) {
            if (isBlank(arg)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断字符串数组或列表是否包含null或空字串对象
     *
     * <pre>
     * StringUtils.isContainEmpty(null,"xxx")     =true
     * StringUtils.isContainEmpty("","xxx")       =true
     * StringUtils.isContainEmpty(" ","xxx")      =false
     * StringUtils.isContainEmpty("bob","xxx")    =false
     * StringUtils.isContainEmpty("  bob ","xxx")   =false
     * </pre>
     */
    public static boolean isContainEmpty(String... args) {
        if (args == null) {
            return false;
        }
        for (String arg : args) {
            if (isEmpty(arg)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 将对象转化为字符串,默认UTF8字符集<br/>
     * 1. Byte数组和ByteBuffer会被转化为对应字符串的数组
     * 2. 对象数组会调用Arrays.toString方法
     * 3. 默认调用 toString方法
     */
    public static String toStr(final Object obj) {
        return StringFormatter.toStr(obj, StringFormatter.UTF_8);
    }
}
